package com.dmsdbj.itoo.handler;

import com.dmsdbj.itoo.exception.ItooException;
import com.dmsdbj.itoo.exception.OnlineExamException;
import com.dmsdbj.itoo.resultvoutil.ResultVO;
import com.dmsdbj.itoo.resultvoutil.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
@Slf4j
public class OnlineExamExceptionHandler {


    /**
     * 处理所有不可知的异常
     * @param e
     * @return
     */
    @ExceptionHandler(OnlineExamException.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.FORBIDDEN)     //根据返回的状态码，可选填
    ResultVO handleOnlineExamException(OnlineExamException e){

        log.error(e.getMessage(), e);
        return ResultVOUtil.error(2222, e.getMessage());
    }


    /**
     * 处理所有不可知的异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    ResultVO handleException(Exception e){

        log.error(e.getMessage(), e);
        return ResultVOUtil.error(1111, e.getMessage());
    }


}
